

function log(str){
	if(window.console)
		console.log(str);
}

$(document).ready(function(){
	var action = $("input[name='action']").val();
	$(".nav li a[href='"+action+"']").parent().attr("class", "active");
	
	//用户头像不存在的，则替换成默认的头像
	$("img").each(function (i,e){
		var imgsrc = $(e).attr("src");
		if($.trim(imgsrc)==""){
			$(e).attr("src", $(this).attr("default"));
		}
				
		$(e).load(function(){
			//ok
			if(window.console){
				console.log("load ok @ "+ $(e).attr("src") );
			}
		}).error(function() {
			$(e).attr("src", $(this).attr("default"));
		});
	});
	
	
	 if( typeof(Messenger)=="undefined"){
		 var html = "";
		 html += "<!-- Message plug -->";
		 html += "	<script src=\"plugins/HubSpotMessager/build/js/messenger.js\"></script>";
		 html += "<link href=\"plugins/HubSpotMessager/build/css/messenger.css\" rel=\"stylesheet\" />";
		 html += "<link href=\"plugins/HubSpotMessager/build/css/messenger-theme-air.css\" rel=\"stylesheet\" />";
		 html += "<link href=\"plugins/HubSpotMessager/build/css/messenger-theme-block.css\" rel=\"stylesheet\" />";
		 html += "<link href=\"plugins/HubSpotMessager/build/css/messenger-theme-flat.css\" rel=\"stylesheet\" />";
		 html += "<link href=\"plugins/HubSpotMessager/build/css/messenger-theme-future.css\" rel=\"stylesheet\" />";
		 html += "<link href=\"plugins/HubSpotMessager/build/css/messenger-theme-ice.css\" rel=\"stylesheet\" />";
		 $("head").append( html );
	 }
	
});

var winAlert = window.alert;
window.alert = function(msg){
	if(window.top.alertMsg)
		window.top.alertMsg(msg);
	else if( typeof(Messenger)!="undefined"){
		//HubSpot Messager 
		Messenger.options = {
		    extraClasses: 'messenger-fixed messenger-on-top', // messenger-on-right
		    theme: 'flat'
		}
		Messenger().post({
			 message: msg,
			 type: 'error',
			 showCloseButton: true
		});
		
	}else{
		winAlert(msg);
	}
}





